package com.xgk.boot.module.core.controller.admin.product;


import com.xgk.boot.framework.common.pojo.CommonResult;
import com.xgk.boot.framework.common.pojo.PageResult;
import com.xgk.boot.module.core.controller.admin.customer.vo.CustomerVO;
import com.xgk.boot.module.core.controller.admin.product.vo.product.*;
import com.xgk.boot.module.core.dal.iservice.ProductCustomerService;
import com.xgk.boot.module.core.dal.iservice.ProductService;
import com.xgk.boot.module.core.service.product.ProductCustomerServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;

import static com.xgk.boot.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 产品分配")
@RestController
@RequestMapping("/admin/product/distribute")
public class ProductDistributeController {

    @Resource
    private ProductCustomerServiceImpl productCustomerService;


    @PutMapping("/customer/{id}")
    @Operation(summary = "修改客户产品分配")
    @Parameter(name = "id", description = "客户id", required = true, example = "1934923143484133377")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<Boolean> updateCustomerProduct(@PathVariable("id") Long id,@RequestBody List<ProductInfoVO> customerVOS) {
        return success(productCustomerService.updateCustomerProduct(id,customerVOS));
    }

    @PutMapping("/product/{id}")
    @Operation(summary = "修改产品客户分配")
    @Parameter(name = "id", description = "产品id", required = true, example = "1934923143484133377")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<Boolean> updateProductCustomer(@PathVariable("id") Long id,@RequestBody List<CustomerVO> customerVOS) {
        return success( productCustomerService.updateProductCustomer(id,customerVOS));
    }


    @PostMapping("/customer/page")
    @Operation(summary = "获取商品详细配置")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<PageResult<CustomerProductVO>> getListByCustomer(@RequestBody ProductDistbuteReqVO pageReqVO) {
        PageResult<CustomerProductVO> customerProductVOPageResult = productCustomerService.pageListByCustomer(pageReqVO);
        return success(customerProductVOPageResult);
    }

    @PostMapping("/product/page")
    @Operation(summary = "获得产品分页")
    @PreAuthorize("@ss.hasPermission('system:admin')")
    public CommonResult<PageResult<ProductCustomerVO>> getListByProduct(@RequestBody ProductDistbuteReqVO pageReqVO) {
        PageResult<ProductCustomerVO> productCustomerVOPageResult = productCustomerService.pageListByProduct(pageReqVO);
        return success(productCustomerVOPageResult);
    }


 

}
